package net.bithappens.hnqe.graph;

import java.net.URI;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import net.bithappens.hnqe.IllegalParamException;

public class GraphNode extends GraphRelationMember {

	private String type;
	
	private Collection<EntryProperty> properties = new LinkedList<EntryProperty>();

	public GraphNode(String type, URI uri, Date lease) throws IllegalParamException {
		super(uri, lease);
		
		if(type == null || type.isEmpty()){
			throw new IllegalParamException("the nodeType must not be null or empty");
		}
		
		this.type = type;
		
	}

	public GraphNode(String type, URI uri, Date lease, List<EntryProperty> properties)	throws IllegalParamException {
		super(uri, lease);
		
		if(type == null || type.isEmpty()){
			throw new IllegalParamException("the nodeType must not be null or empty");
		}
		
		this.type = type;
		this.properties = properties;
		
	}

	@Override
	public String getTypeId() {
		return type;
	}
	
	public void setNodeClass(String nodeClass) {
		this.type = nodeClass;
	}

	public Collection<EntryProperty> getProperties() {
		return properties;
	}
		
	public void addProperty(EntryProperty properties) {
		this.properties.add(properties);
	}
	
	public void addProperty(String name, EntryValue value) throws IllegalParamException {
		this.properties.add(new EntryProperty(name, value));
	}
	
	public void setProperties(Collection<EntryProperty> properties) {
		this.properties = properties;
	}
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getUri() == null) ? 0 : getUri().hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GraphNode other = (GraphNode) obj;
		if (getUri() == null) {
			if (other.getUri() != null)
				return false;
		} else if (!getUri().equals(other.getUri()))
			return false;
		return true;
	}

	@Override
	public String toString() {
		String propertiesAsString = "";
		
		for(EntryProperty property : properties){
			propertiesAsString += property +",";
		}
		
		return "GraphNode ["+type+" - "+getUri().toString()+" {"+propertiesAsString+"}]";
		
	}

}
